#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<iostream>
#include<vector>
#include<queue>

using namespace std;


  struct TreeNode 
  {
     int val;
      TreeNode *left;
      TreeNode *right;
      TreeNode() : val(0), left(nullptr), right(nullptr) {}
     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
  };
 
class Solution
{
public:
    vector<vector<int>> levelOrderBottom(TreeNode* root)
    {
        auto ret = vector<vector<int>>();
        if (root == nullptr) return ret;

        queue<TreeNode*> q;
        q.push(root);

        while (!q.empty())
        {
            auto level = vector<int>();
            int size = q.size();

            for (int i = 0; i < q.size(); i++)
            {
                auto node = q.front();
                q.pop();
                level.push_back(node->val);

                if (node->left) q.push(node->left);
                if (node->right) q.push(node->right);
            }
            ret.push_back(level);
        }
        reverse(ret.begin(), ret.end());
        return ret;
    }
};

int main()
{
    TreeNode* root = nullptr;
    root->val = 3;
    root->left->val = 9;
    root->right->val = 20;
    root->right->left->val = 15;
    root->right->right->val = 7;

    return 0;
}